package com.qijian.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qijian.common.core.controller.BaseController;
import com.qijian.common.core.domain.AjaxResult;
import com.qijian.common.core.page.TableDataInfo;
import com.qijian.common.utils.mybatis.WhereEntityTool;
import com.qijian.system.domain.ExpireConfig;
import com.qijian.system.domain.vo.ExpireConfigQuery;
import com.qijian.system.domain.vo.ExpireConfigVo;
import com.qijian.system.service.IExpireConfigService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "系统管理：邮件升级提醒")
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/expire")
public class ExpireConfigController extends BaseController {

    private final IExpireConfigService expireConfigService;

    @GetMapping("/list")
    public TableDataInfo list(ExpireConfigQuery query, IPage<ExpireConfig> page) {
//        initOrderItem(ExpireConfig.class, page.orders());
        QueryWrapper<ExpireConfig> queryWrapper = WhereEntityTool.invoke(query);
        queryWrapper.orderByDesc("update_time");
        return getDataTable(expireConfigService.page(Page.of(page.getCurrent(), page.getSize()),queryWrapper));
    }

    /***
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(expireConfigService.getInfo(id));
    }

    /***
     * 新增
     * @param vo
     * @return
     */
    @PostMapping
    public AjaxResult add(@RequestBody ExpireConfigVo vo) {
        return toAjax(expireConfigService.saveOrUpdateConfig(vo));
    }

    /**
     * 修改
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ExpireConfigVo vo) {
        return toAjax(expireConfigService.saveOrUpdateConfig(vo));
    }

    /***
     * 删除
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(expireConfigService.removeExpireConfig(ids));
    }


    /***
     * 修改状态
     * @param expireConfigVo
     * @return
     */
    @PostMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody ExpireConfigVo expireConfigVo){
        return toAjax(expireConfigService.updateStatus(expireConfigVo));
    }

}
